//
//  WNRegexManager.swift
//  WalkNovel
//
//  Created by Kevin on 2023/7/4.
//

import UIKit
import ChameleonFramework

struct WNRegex {
    /// 邮箱号
    static let emailPattern = "[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}"
    /// 昵称正则
    static let namePattern = "^[\\w\\u4e00-\\u9fa5]{1,30}$"
    /// 验证码
    static let codePattern = "^\\d{6}$"
    //// 密码
    static let passwordPattern = "^(?![0-9]+$)(?![a-zA-Z]+$)(?![^0-9a-zA-Z]+$).{6,20}$"
    /// 用户名长度
    static let NameMaxLen = 30
    /// 评论长度
    static let CommentMaxLen = 2000
    /// 评分长度
    static let RateMaxLen = 300
    /// 反馈长度
    static let FeedbackMaxLen = 500
    
    
    // MARK: - 验证
    let regex: NSRegularExpression?
    
    init(_ pattern: String) {
        regex = try? NSRegularExpression(pattern: pattern, options: .caseInsensitive)
    }
    
    func match(input: String) -> Bool {
        if let matches = regex?.matches(in: input, options: [], range: NSMakeRange(0, input.count)) {
            return matches.count > 0
        }else {
            return false
        }
    }
    
    /// 正则替换字符
    func wn_replaceChar(_ str: String, _ template: String) -> String {
        if let matches = regex?.stringByReplacingMatches(in: str, options: .reportProgress, range: NSMakeRange(0, str.count), withTemplate: template) {
            return matches
        }else {
            return str
        }
    }
}

struct WNColor {
    
    struct Fade {
        func left2right(_ size: CGSize) -> UIColor {
            return GradientColor(.leftToRight, frame: CGRect(x: 0, y: 0, width: size.width, height: size.height), colors: [#colorLiteral(red: 0.9960784314, green: 0.5843137255, blue: 0.7058823529, alpha: 1), #colorLiteral(red: 0.9960784314, green: 0.3882352941, blue: 0.5647058824, alpha: 1)])
        }
        
        func top2Bottom(_ size: CGSize) -> UIColor {
            return GradientColor(.topToBottom, frame: CGRect(x: 0, y: 0, width: size.width, height: size.height), colors: [#colorLiteral(red: 1, green: 0.8125284489, blue: 1, alpha: 1), #colorLiteral(red: 0.968627451, green: 0.968627451, blue: 0.968627451, alpha: 1)])
        }
        
        func lockTop2Bottom(_ size: CGSize) -> UIColor {
            return GradientColor(.topToBottom, frame: CGRect(x: 0, y: 0, width: size.width, height: size.height), colors: isDark() ? [#colorLiteral(red: 0.07058823529, green: 0.07058823529, blue: 0.07058823529, alpha: 0.05), #colorLiteral(red: 0.07058823529, green: 0.07058823529, blue: 0.07058823529, alpha: 0.2), #colorLiteral(red: 0.07058823529, green: 0.07058823529, blue: 0.07058823529, alpha: 0.35), #colorLiteral(red: 0.07058823529, green: 0.07058823529, blue: 0.07058823529, alpha: 0.5), #colorLiteral(red: 0.07058823529, green: 0.07058823529, blue: 0.07058823529, alpha: 0.65), #colorLiteral(red: 0.07058823529, green: 0.07058823529, blue: 0.07058823529, alpha: 0.7), #colorLiteral(red: 0.07058823529, green: 0.07058823529, blue: 0.07058823529, alpha: 0.95)] : [#colorLiteral(red: 1, green: 0.9999999404, blue: 1, alpha: 0.05), #colorLiteral(red: 1, green: 0.9999999404, blue: 1, alpha: 0.15), #colorLiteral(red: 1, green: 0.9999999404, blue: 1, alpha: 0.3), #colorLiteral(red: 1, green: 0.9999999404, blue: 1, alpha: 0.45), #colorLiteral(red: 1, green: 1, blue: 1, alpha: 0.6), #colorLiteral(red: 1, green: 1, blue: 1, alpha: 0.75), #colorLiteral(red: 1, green: 0.9999999404, blue: 1, alpha: 0.9)])
        }
    }
}
